/*
 * @Description: 静态错误捕捉
 * @Author: IA ia@kepro.space
 * @Date: 2025-03-14 00:48:32
 */


// 如果执行过程有错误，则捕捉并赋值给返回数组的第一个元素
async function silentHandle<T, U = Error>(fn: Function, ...args:Array<unknown>): Promise<[U, null] | [null, T]> {

    let result: [U, null] | [null, T]

    try {
        result = [null, await fn(...args)]
    } catch (e:any) {
        result = [e, null]
    }

    return result

}

export default silentHandle